package fule.com.playandroidkotlin.ui.activity

import com.google.android.material.tabs.TabLayout
import java.util.ArrayList

import fule.com.playandroidkotlin.base.BaseActivity
import fule.com.kotlindemo.base.BaseView
import fule.com.playandroidkotlin.R
import fule.com.playandroidkotlin.base.BasePresenter
import fule.com.playandroidkotlin.ui.adapter.KnowledgePagerAdapter
import fule.com.playandroidkotlin.ui.model.ChildrenBean
import fule.com.playandroidkotlin.ui.util.AppConstant
import kotlinx.android.synthetic.main.activity_test.*
import kotlinx.android.synthetic.main.toolbar.*

/**
 * 作者： njb
 * 时间： 2018/8/14 0014-下午 1:42
 * 描述：
 * 来源：
 */
class TestActivity : BaseActivity<BasePresenter<BaseView>>() {


    private var data: List<ChildrenBean> = ArrayList()
    private var id: String? = null
    private var titles: String? = null
    private var knowledges: MutableList<ChildrenBean>? = null

    private val viewPagerAdapter: KnowledgePagerAdapter by lazy {
        KnowledgePagerAdapter(knowledges!!, supportFragmentManager)
    }

    override val layoutId: Int
        get() = R.layout.activity_test

    override fun createPresenter(): BasePresenter<BaseView> {
        return BasePresenter(this)
    }

    override fun initView() {
        if (intent != null && intent.extras != null) {
            intent.extras.let {
                id = intent.extras!!.getString(AppConstant.ARTICLELIST_ID)
                titles = intent.extras!!.getString(AppConstant.ARTICLELIST_TITLE)
                knowledges = (intent.getParcelableArrayListExtra(AppConstant.CONTENT_DATA_KEY))
            }
        }
        initToolBar()
        initTab()
        initAdapter()
    }

    private fun initTab() {
        viewPager.run {
            adapter = viewPagerAdapter
            addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout))
            offscreenPageLimit = knowledges!!.size
        }
        tabLayout.run {
            setupWithViewPager(viewPager)
            // TabLayoutHelper.setUpIndicatorWidth(tabLayout)
            addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(viewPager))
        }

    }

    private fun initToolBar() {
        toolbar.run {
            toolbar.title = titles
            setSupportActionBar(this)
            supportActionBar?.setDisplayHomeAsUpEnabled(true)
        }

    }

    private fun initAdapter() {
    }


    override fun addListener() {

    }

    override fun showLoading() {
    }

    override fun hideLoading() {
    }

}


